<?php
/**
 * Created by PhpStorm.
 * User: Apache
 *  广告类别
 *
 */

namespace app\api\controller\activemanage;
use app\api\controller\common\ApiBase;
use think\Db;
use think\Model;
use app\api\model\Admin as AdminModel;
use app\api\controller\common\CommonPlus;
use think\Controller; // dengh quxiao
// Controller  ApiBase （dengl）
class Zhguanggaolb extends ApiBase
{

    protected $admin;
    protected $model = null;
    public function _initialize()
    {
        parent::_initialize();
        $this->admin = session('admin');
        //$this->model = model('CompanyPublic');
    }


    /**
     * 根据公海id获得获取
     * @return \think\response\Json|void
     *  http://dxshowxya.for.pub/index.php?s=/api/basemanage/Yuyuemanage/getList
     */

     public function getTabName($exhibition_id){
        $result=db('exhibition')->where(['id'=>$exhibition_id])->find();
        if($result){
            $tabName=$result['create_tablename'];
        }else{
            return json(['code'=>0,'msg'=>'缺少关键字段','data'=>'']);
        }
        return $tabName;
     } 

     /**
     *
     * @return \think\response\Json|void
     *  comppub
     *  广告类别联  ？
     */

    public function index(){
        $sql2="select * from crm_zh_guanggao_catecory where is_del=0 order by id desc";
        $list=Db::query($sql2);
        return json(['code'=>1,'msg'=>'success','data'=>$list]);
    }


 
    /**
     *  添加 环节
     */
    public function add(){
        $data['create_time']=time();
        $data['title']=$this->request->param('title');
        $res=db('zh_guanggao_catecory')->insert($data);
        if(!$res){
            return json(['code'=>0,'msg'=>'操作失败','data'=>'']);
        }
        return json(['code'=>1,'msg'=>'操作成功','data'=>'']);
    }


    /**
     * 删除 环节
     */
    public function del(){
        $id = $this->request->param('id');
        $r = db('zh_guanggao_catecory')->where(['id'=>$id])->find();
        if(!$r){
            return json(['code'=>0,'msg'=>'记录不存在','data'=>'']);
        }
        $r=db('zh_guanggao_catecory')->where(['id'=>$id])->update(['is_del'=>1]);
        if(!$r){
            return json(['code'=>0,'msg'=>'操作失败，请重试','data'=>'']);
        }
        return json(['code'=>1,'msg'=>'操作成功','data'=>'']);
    }
    /**
     * 批量删除环节
     */
    public function delall(){
        $com =new CommonPlus();
        $tabName='crm_zh_guanggao_catecory';
        $id = $this->request->param('id');
        $ids = explode(',',$id);
        if(empty($id)){
            return json(['code'=>0,'msg'=>'参数有误','data'=>'']);
        }
        foreach ($ids as $id){
            $where['id'] = $id;
            $r=$com->sel_com_one('222', $where, $tabName);   

            if(!$r){
                return json(['code'=>0,'msg'=>'id:'.$id.'记录不存在,批量删除失败','data'=>'']);
            }else{
                $where1['id'] = $id;
                $data['is_del']=1;
                $r=$com->edit_com_fxlist($data, $where1, $tabName);
                if(!$r){
                    return json(['code'=>0,'msg'=>'id:'.$id.'删除失败','data'=>'']);
                }
            }
      
            
        }

        return json(['code'=>1,'msg'=>'操作成功','data'=>'']);
    }


    /**
     * 基本信息修改 环节
     * @return \think \response\Json|void
     */
    public function edit()
    {
        $id = $this->request->param('id');
        $r = db('zh_guanggao_catecory')->where(['id'=>$id])->find();
        if(!$r){
            return json(['code'=>0,'msg'=>'记录不存在','data'=>'']);
        }
        $data['update_time']=time();
        $data['title']=$this->request->param('title');
        $r=db('zh_guanggao_catecory')->where(['id'=>$id])->update($data);
        if (!$r) {
            return json(['code' => 0, 'msg' => '操作失败，请重试']);
        }
        return json(['code' => 1, 'msg' => '操作成功']);
    }


    public function indexs(){
        $sql2="select * from crm_zh_guanggao_type where is_del=0 order by id desc";
        $list=Db::query($sql2);
        return json(['code'=>1,'msg'=>'success','data'=>$list]);
    }


 
    /**
     *  添加 环节
     */
    public function adds(){
        $data['create_time']=time();
        $data['title']=$this->request->param('title');
        $res=db('zh_guanggao_type')->insert($data);
        if(!$res){
            return json(['code'=>0,'msg'=>'操作失败','data'=>'']);
        }
        return json(['code'=>1,'msg'=>'操作成功','data'=>'']);
    }


    /**
     * 删除 环节
     */
    public function dels(){
        $id = $this->request->param('id');
        $r = db('zh_guanggao_type')->where(['id'=>$id])->find();
        if(!$r){
            return json(['code'=>0,'msg'=>'记录不存在','data'=>'']);
        }
        $r=db('zh_guanggao_type')->where(['id'=>$id])->update(['is_del'=>1]);
        if(!$r){
            return json(['code'=>0,'msg'=>'操作失败，请重试','data'=>'']);
        }
        return json(['code'=>1,'msg'=>'操作成功','data'=>'']);
    }
    /**
     * 批量删除环节
     */
    public function delalls(){
        $com =new CommonPlus();
        $tabName='zh_guanggao_type';
        $id = $this->request->param('id');
        $ids = explode(',',$id);
        if(empty($id)){
            return json(['code'=>0,'msg'=>'参数有误','data'=>'']);
        }
        foreach ($ids as $id){
            $where['id'] = $id;
            $r=$com->sel_com_one('222', $where, $tabName);   

            if(!$r){
                return json(['code'=>0,'msg'=>'id:'.$id.'记录不存在,批量删除失败','data'=>'']);
            }else{
                $where1['id'] = $id;
                $data['is_del']=1;
                $r=$com->edit_com_fxlist($data, $where1, $tabName);
                if(!$r){
                    return json(['code'=>0,'msg'=>'id:'.$id.'删除失败','data'=>'']);
                }
            }
      
            
        }

        return json(['code'=>1,'msg'=>'操作成功','data'=>'']);
    }


    /**
     * 基本信息修改 环节
     * @return \think \response\Json|void
     */
    public function edits()
    {
        $id = $this->request->param('id');
        $r = db('zh_guanggao_type')->where(['id'=>$id])->find();
        if(!$r){
            return json(['code'=>0,'msg'=>'记录不存在','data'=>'']);
        }
        $data['update_time']=time();
        $data['title']=$this->request->param('title');
        $r=db('zh_guanggao_type')->where(['id'=>$id])->update($data);
        if (!$r) {
            return json(['code' => 0, 'msg' => '操作失败，请重试']);
        }
        return json(['code' => 1, 'msg' => '操作成功']);
    }


}
